<template>
  <el-dialog title="报工项选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal= false
    width="70%"
    center
  >
    <el-table v-loading="loading" :data="rworkList" highlight-current-row @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
      <el-table-column  width="55" align="center" >
          <template v-slot="scope">
              <el-radio v-model="selectedId" :label="scope.row.rworkId" @change="handleRowChange(scope.row)">{{""}}</el-radio>
          </template>
      </el-table-column>
      <el-table-column label="车间" align="center" prop="slWorkshop.workshopName" />
       <el-table-column label="大工序" align="center" prop="slGprocess.gprocessName" />
       <el-table-column label="小工序" align="center" prop="slProcess.processName" />
      <el-table-column label="生产鼓号" align="center" prop="wtermDnumber" />
      <el-table-column label="订单编号" align="center" prop="wtermOnumber" />
      <el-table-column label="品种" align="center" prop="breed.breedName" />
      <el-table-column label="颜色" align="center" prop="colour.colourName" />
      <el-table-column label="工艺要求" align="center" prop="rworkTr" />
      <el-table-column label="单位" align="center" prop="rworkDw" />
      <el-table-column label="计划生产" align="center" prop="rworkPlan" />
      <el-table-column label="实际生产" align="center" prop="rworkActual" />
      <el-table-column label="工序单价" align="center" prop="processPay" />
      <el-table-column label="工作时长" align="center" prop="rworkDuration" />
      <el-table-column label="预估工资" align="center" prop="estimatePay" />
      <el-table-column fixed="right" label="操作" width="120" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>

   <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详细报工单对话框 -->
    <el-dialog title="报工项详细" :visible.sync="open" width="960px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="生产鼓号/生产批号" label-width="140px" prop="wtermDnumber">
              {{form.wtermDnumber}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单编号"  prop="wtermOnumber">
              {{form.wtermOnumber}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="模块" prop="moduleId">
              {{ form.slModule != null ? form.slModule.moduleName : '' }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车间" prop="workshopId">
              {{ form.slWorkshop != null ? form.slWorkshop.workshopName : '' }}
            </el-form-item>
          </el-col>
           <el-col :span="8">
             <el-form-item label="大工序">
               {{ form.slGprocess != null ? form.slGprocess.gprocessName : '' }}
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
            <el-col :span="8">
              <el-form-item label="小工序" prop="processId">
                {{ form.slProcess != null ? form.slProcess.processName : '' }}
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="工序单价" prop="processPay">
                {{form.processPay}}
              </el-form-item>
           </el-col>
          <el-col :span="8">
            <el-form-item label="品种" prop="breedId">
              {{ form.breed != null ? form.breed.breedName : '' }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
           <el-form-item label="颜色" prop="colourId">
             {{ form.colour != null ? form.colour.colourName : '' }}
           </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工艺要求" prop="rworkTr">
              {{form.rworkTr}}
            </el-form-item>
          </el-col>
           <el-col :span="8">
                <el-form-item label="单位" prop="rworkDw">
                  {{form.rworkDw}}
                </el-form-item>
             </el-col>
        </el-row>
          <el-row>
          <el-col :span="8">
           <el-form-item label="计划生产" prop="rworkPlan">
             {{form.rworkPlan}}
          </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="实际生产" prop="rworkActual">
              {{form.rworkActual}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="重复次数" prop="rworkRepetitions">
              {{form.rworkRepetitions}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
          <el-form-item label="开始时间" prop="rworkStart">
            {{form.rworkStart}}
          </el-form-item>
          </el-col>
          <el-col :span="8">
          <el-form-item label="结束时间" prop="rworkEnd">
            {{form.rworkEnd}}
          </el-form-item>
          </el-col>
          <el-col :span="8">
           <el-form-item label="工作时长" prop="rworkDuration">
             {{form.rworkDuration}}
           </el-form-item>
          </el-col>
           </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="预估工资" prop="estimatePay">
              {{form.estimatePay}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center">操作人</el-divider>
          <el-table :data="slRworkRmemberList" :row-class-name="rowSlRworkRmemberIndex" ref="slRworkRmember" style="width:100%">
            <el-table-column label="序号" align="center" prop="index" width="50"/>
            <el-table-column label="参与人" prop="rmemberNick"  />
            <el-table-column label="职级" prop="levelName"  />
            <el-table-column label="计薪方式" prop="ssmName"  />
            <el-table-column label="班组" prop="rmemberBz"  >
              <template slot-scope="scope">
                  <dict-tag :options="dict.type.sl_rwork_class" :value="scope.row.rmemberBz"/>
                </template>
            </el-table-column>
          </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>

  </el-dialog>
</template>

<script>
import { listRwork, getRwork, listRworkByrfworkId } from "@/api/sl/rwork";

export default {
  name: "RworkSelect",
  dicts: ['sl_rwork_class'],
  data() {
    return {
      showFlag:false,
      // 选中数组
      selectedId: null,
      selectedRow: null,
      visible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报工单表格数据
      rworkList: [],
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rfworkId: null
      },
      gprocessOptions: [],
      processOptions: [],
      moduleOptions:[],
      workshopOptions:[],
       // 操作人表格数据
      slRworkRmemberList: [],
    };
  },
  // created() {
  //   this.getList();
  // },
  methods: {
    show(rfworkId){
      this.queryParams.rfworkId = rfworkId;
      this.getList();
      this.showFlag = true;
    },
    /** 查询报工单列表 */
    getList() {
      this.loading = true;
      listRworkByrfworkId(this.queryParams.rfworkId).then(response => {
        this.rworkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rworkId: null,
        rworkDate: null,
        moduleId: null,
        workshopId: null,
        rworkBz: null,
        rworkYear: null,
        rworkMonth: null,
        rworkDay: null,
        isApproved: null,
        createBy: null,
        createTime: null,
        leaderUser: null,
        wtermDnumber: null,
        wtermOnumber: null,
        gprocessId: null,
        processId: null,
        breedId: null,
        colourId: null,
        rworkTr: null,
        rworkDw: null,
        rworkPlan: null,
        rworkActual: null,
        rworkStart: null,
        rworkEnd: null,
        rworkDuration: null,
        processPay: null,
        estimatePay: null,
        rworkRepetitions: 1,
        rworkUser: null,
        rworkDm: null,
        rfworkId: null,
        wtermBatch: null,
        actualBatch: null,
      };
      this.slRworkRmemberList = [];
      this.resetForm("form");
    },

    /** 详细按钮操作 */
    handleDetail(row) {
      this.reset();
      const rworkId = row.rworkId
      getRwork(rworkId).then(response => {
        this.form = response.data;
        this.gprocessOptions = response.gprocesss;
        this.processOptions = response.processs;
        this.moduleOptions = response.modules;
        this.workshopOptions = response.workshops;
        this.slRworkRmemberList = response.data.slRworkRmemberList;
        this.open = true;
        this.title = "报工单详细";
      });
    },
    	/** 操作人序号 */
    rowSlRworkRmemberIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    //单击选中
    handleCurrent(row){
      if(row){
          this.selectedRow = row;
      }
    },
    //行双击选中
    handleRowDbClick(row){
      if(row){
        this.selectedRow = row;
        this.$emit('onSelected',this.selectedRow);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if(row){
        this.selectedRow = row;
      }
    },
    confirmSelect(){
      if(this.selectedId == null || this.selectedId == 0){
        this.$notify({
          title:'提示',
          type:'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected',this.selectedRow);
      this.showFlag = false;
    }
  }
}
</script>
<style>
.el-table .el-table__body-wrapper::-webkit-scrollbar {
    height: 10px;
}
</style>
